home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Filling Shapes with a Gradient Brush / Creating a Path Gradient / GDITEST7.dpr
Encoding:
Text File  |  2003-10-15  |  3.1 KB  |  114 lines

  1. program GDITEST7;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   path: TGPGraphicsPath;
  14.   pthGrBrush: TGPPathGradientBrush;
  15.   count: Integer;
  16. const
  17.   colors: array[0..0] of TGPColor = (aclAqua);
  18. begin
  19.   graphics := TGPGraphics.Create(DC);
  20.  
  21.   // Create a path that consists of a single ellipse.
  22.   path:= TGPGraphicsPath.Create;
  23.   path.AddEllipse(0, 0, 140, 70);
  24.  
  25.   // Use the path to construct a brush.
  26.   pthGrBrush := TGPPathGradientBrush.Create(path);
  27.  
  28.   // Set the color at the center of the path to blue.
  29.   pthGrBrush.SetCenterColor(MakeColor(255, 0, 0, 255));
  30.  
  31.   count := 1;
  32.   pthGrBrush.SetSurroundColors(@colors, count);
  33.  
  34.   graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70);
  35.  
  36.   // By default, a path gradient brush does not extend outside the boundary of
  37.   // the path. If you use the path gradient brush to fill a shape that extends
  38.   // beyond the boundary of the path, the area of the screen outside the path
  39.   // will not be filled. The following illustration shows what happens if you
  40.   // change the FillEllipse call in the preceding code to
  41.   // graphics.FillRectangle(pthGrBrush, 0, 10, 200, 40);
  42.  
  43.   path.Free;
  44.   pthGrBrush.Free;
  45.   graphics.Free;
  46. end;
  47.  
  48.  
  49. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  50. var
  51.   Handle: HDC;
  52.   ps: PAINTSTRUCT;
  53. begin
  54.   case message of
  55.     WM_PAINT:
  56.       begin
  57.         Handle := BeginPaint(Wnd, ps);
  58.         OnPaint(Handle);
  59.         EndPaint(Wnd, ps);
  60.         result := 0;
  61.       end;
  62.  
  63.     WM_DESTROY:
  64.       begin
  65.         PostQuitMessage(0);
  66.         result := 0;
  67.       end;
  68.  
  69.    else
  70.       result := DefWindowProc(Wnd, message, wParam, lParam);
  71.    end;
  72. end;
  73.  
  74. var
  75.   hWnd     : THandle;
  76.   Msg      : TMsg;
  77.   wndClass : TWndClass;
  78. begin
  79.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  80.    wndClass.lpfnWndProc    := @WndProc;
  81.    wndClass.cbClsExtra     := 0;
  82.    wndClass.cbWndExtra     := 0;
  83.    wndClass.hInstance      := hInstance;
  84.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  85.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  86.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  87.    wndClass.lpszMenuName   := nil;
  88.    wndClass.lpszClassName  := 'GettingStarted';
  89.  
  90.    RegisterClass(wndClass);
  91.  
  92.    hWnd := CreateWindow(
  93.       'GettingStarted',       // window class name
  94.       'Creating a Path Gradient',       // window caption
  95.       WS_OVERLAPPEDWINDOW,    // window style
  96.       Integer(CW_USEDEFAULT), // initial x position
  97.       Integer(CW_USEDEFAULT), // initial y position
  98.       Integer(CW_USEDEFAULT), // initial x size
  99.       Integer(CW_USEDEFAULT), // initial y size
  100.       0,                      // parent window handle
  101.       0,                      // window menu handle
  102.       hInstance,              // program instance handle
  103.       nil);                   // creation parameters
  104.  
  105.    ShowWindow(hWnd, SW_SHOW);
  106.    UpdateWindow(hWnd);
  107.  
  108.    while(GetMessage(msg, 0, 0, 0)) do
  109.    begin
  110.       TranslateMessage(msg);
  111.       DispatchMessage(msg);
  112.    end;
  113. end.
  114.